package com.yanqu.road.entity.activity.daomu.pvp;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 盗墓笔记pvp房间信息
 */
@FieldTypeAnnotation(tableName = "t_c_activity_daomu_pvp_room_data")
public class DaoMuPvpRoomData extends DataObject {

    /**
     * 活动id
     */
    private int activityId;

    /**
     * 房间id
     */
    private int roomId;

    /**
     * 层数
     */
    private int floor;

    /**
     * 是否坍塌
     */
    private boolean collapse;

    /**
     * 收圈时间
     */
    private long shrinkStartTime;

    /**
     * 出生点信息
     * 不入库
     */
    private List<DaoMuPvpBirthData> birthDataList = new ArrayList<>();

    /**
     * 宝箱信息
     * 不入库
     */
    private List<DaoMuPvpBoxData> boxDataList = new ArrayList<>();

    /**
     * 物资信息
     * 不入库
     */
    private Map<String, DaoMuPvpGoodsData> goodsDataMap = new ConcurrentHashMap<>();


    /**
     * 房间的怪物信息
     * 不入库
     */
    private Map<String, DaoMuPvpMonsterData> monsterDataMap = new ConcurrentHashMap<>();

    /**
     * 上次怪物寻找目标时间,不入库
     */
    private long lastMonsterFindUserTime;

    /**
     * 计数
     */
    private long handlerMonsterMoveCnt = 0;

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setOp(DataStatus.Update);
        }
    }

    public int getRoomId() {
        return roomId;
    }

    public void setRoomId(int roomId) {
        if (this.roomId != roomId) {
            this.roomId = roomId;
            setOp(DataStatus.Update);
        }
    }

    public int getFloor() {
        return floor;
    }

    public void setFloor(int floor) {
        if (this.floor != floor) {
            this.floor = floor;
            setOp(DataStatus.Update);
        }
    }

    public long getLastMonsterFindUserTime() {
        return lastMonsterFindUserTime;
    }

    public void setLastMonsterFindUserTime(long lastMonsterFindUserTime) {
        this.lastMonsterFindUserTime = lastMonsterFindUserTime;
    }

    public List<DaoMuPvpBirthData> getBirthDataList() {
        return birthDataList;
    }

    public void setBirthDataList(List<DaoMuPvpBirthData> birthDataList) {
        this.birthDataList = birthDataList;
    }

    public List<DaoMuPvpBoxData> getBoxDataList() {
        return boxDataList;
    }

    public void setBoxDataList(List<DaoMuPvpBoxData> boxDataList) {
        this.boxDataList = boxDataList;
    }

    public Map<String, DaoMuPvpGoodsData> getGoodsDataMap() {
        synchronized (goodsDataMap) {
            return new ConcurrentHashMap<>(goodsDataMap);
        }
    }

    public void addGoodsData(DaoMuPvpGoodsData goodsData) {
        synchronized (goodsDataMap) {
            goodsDataMap.put(goodsData.getUid(), goodsData);
        }
    }

    public void removeGoodsData(String uid) {
        synchronized (goodsDataMap) {
            goodsDataMap.remove(uid);
        }
    }

    public void removeAllGoodsData() {
        synchronized (goodsDataMap) {
            goodsDataMap.clear();
        }
    }


    public Map<String, DaoMuPvpMonsterData> getMonsterDataMap() {
        synchronized (monsterDataMap) {
            return new ConcurrentHashMap<>(monsterDataMap);
        }
    }

    public void addMonsterData(DaoMuPvpMonsterData monsterData) {
        synchronized (monsterDataMap) {
            monsterDataMap.put(monsterData.getMonsterId(), monsterData);
        }
    }

    public void removeMonsterData(String monsterId) {
        synchronized (monsterDataMap) {
            monsterDataMap.remove(monsterId);
        }
    }

    public void removeAllMonsterData(){
        synchronized (monsterDataMap) {
            monsterDataMap.clear();
        }
    }

    public boolean isCollapse() {
        return collapse;
    }

    public void setCollapse(boolean collapse) {
        if (this.collapse != collapse) {
            this.collapse = collapse;
            setOp(DataStatus.Update);
        }
    }

    public long getShrinkStartTime() {
        return shrinkStartTime;
    }

    public void setShrinkStartTime(long shrinkStartTime) {
        if (this.shrinkStartTime != shrinkStartTime) {
            this.shrinkStartTime = shrinkStartTime;
            setOp(DataStatus.Update);
        }
    }

    public long getHandlerMonsterMoveCnt() {
        return handlerMonsterMoveCnt;
    }

    public void setHandlerMonsterMoveCnt(long handlerMonsterMoveCnt) {
        this.handlerMonsterMoveCnt = handlerMonsterMoveCnt;
    }

    /**
     * 清除内存无用的数据
     */
    public void clearData() {
        birthDataList.clear();
        boxDataList.clear();
        goodsDataMap.clear();
        monsterDataMap.clear();
    }
}
